package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.jt.tenant.widget.Tools;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

@HttpInlet(Conn.INLET_GET_INS_INFO)
public class GetInsQuote extends JTAsyGet<GetInsQuote.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String userId = JTApplication.jtPreferences.readUserID();

    public GetInsQuote(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        info.phone = body.optString("phone");

        info.ownerName = body.optString("ownerName");

        info.address = body.optString("address");

        info.orderId = body.optString("orderId");

        JSONArray mapList = body.optJSONArray("mapList");

        if(mapList != null){

            for(int i = 0;i<mapList.length();i++){

                JSONObject quote_item = mapList.optJSONObject(i);

                Quote mQuote = new Quote();

                mQuote.id = quote_item.optString("id");

                mQuote.title = quote_item.optString("name");

                mQuote.logo_path = quote_item.optString("path");

                mQuote.message = quote_item.optString("message");

                JSONArray detailList = quote_item.optJSONArray("detailList");

                if(detailList != null){

                    for(int j = 0;j<detailList.length();j++){

                        JSONObject detailItem = detailList.optJSONObject(j);

                        QuoteItem mQuoteItem = new QuoteItem();

                        mQuoteItem.name = detailItem.optString("NAME");

                        mQuoteItem.money = detailItem.optString("BAOE");

                        mQuoteItem.price = "0";

                        mQuoteItem.price = Tools.F_num(detailItem.optString("PRICE"));

                        mQuoteItem.flag = detailItem.optString("FLAG");

                        mQuoteItem.flag_money = detailItem.optString("FLAGMONEY");

                        mQuoteItem.num = detailItem.optString("NUM");

                        mQuote.quoteItemList.add(mQuoteItem);

                    }

                }

                info.quoteList.add(mQuote);

            }

        }

        return info;

    }

    public static class Info {

        public String msg;

        public String phone;

        public String ownerName;

        public String address;

        public String orderId;

        public List<Quote> quoteList = new ArrayList<>();

    }

    public static class Quote {

        public String id;

        public String logo_path;

        public String title;

        public String total;

        public String message;

        public List<QuoteItem> quoteItemList = new ArrayList<>();

        public int flag = 0;//对应保险公司是否被展开

        public int check = 0;//对应保险公司是否被选中

    }

    public static class QuoteItem{

        public String name;

        public String money;

        public String price;

        public String flag;

        public String flag_money;

        public String num;

    }
}
